package com.atguigu.tingshu.search.api;


import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.search.AlbumInfoIndex;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;

    /**
     * 完成建议
     *
     * @param keyword 关键词
     * @return {@link Result }<{@link List }<{@link String }>>
     */
    @GetMapping("/albumInfo/completeSuggest/{keyword}")
    public Result<List<String>> completeSuggest(@PathVariable String keyword) {
        List<String> list = searchService.completeSuggest(keyword);
        return Result.ok(list);
    }

    @GetMapping("/albumInfo/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId) {
        searchService.upperAlbum(albumId);
        return Result.ok();
    }

    @DeleteMapping("/albumInfo/lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable Long albumId) {
        searchService.lowerAlbum(albumId);
        return Result.ok();
    }

    @PostMapping("/albumInfo")
    public Result<AlbumSearchResponseVo> albumInfo(@RequestBody AlbumIndexQuery albumIndexQuery) {
        return Result.ok(searchService.albumInfo(albumIndexQuery));
    }

    @GetMapping("/albumInfo/channel/{category1Id}")
    public Result<List<Map<String, Object>>> getTopCategory3HotAlbumList(@PathVariable Long category1Id) {
        List<Map<String, Object>> list = searchService.getTopCategory3HotAlbumList(category1Id);
        return Result.ok(list);
    }

    /**
     * 获取专辑信息
     *
     * @param albumId 相册id
     * @return 结果<map < string ， 对象>>
     */
    @GetMapping("/albumInfo/{albumId}")
    public Result<Map<String, Object>> getAlbumInfo(@PathVariable Long albumId) {
        Map<String, Object> map = searchService.getAlbumInfo(albumId);
        return Result.ok(map);
    }

    /**
     * 更新最新专辑排名
     *
     * @return 全局统一返回结果类
     */
    @GetMapping("/albumInfo/updateLatelyAlbumRanking")
    public Result updateLatelyAlbumRanking() {
        searchService.updateLatelyAlbumRanking();
        return Result.ok();
    }

    @GetMapping("/albumInfo/findRankingList/{category1Id}/{dimension}")
    public Result<List<AlbumInfoIndex>> findRankingList(@PathVariable Long category1Id, @PathVariable String dimension) {
        List<AlbumInfoIndex> list = searchService.findRankingList(category1Id, dimension);
        return Result.ok(list);
    }


}

